package org.nstack.header.network.l3;

import org.springframework.http.HttpMethod;
import org.nstack.header.identity.Action;
import org.nstack.header.message.APIDeleteMessage;
import org.nstack.header.message.APIEvent;
import org.nstack.header.message.APIMessage;
import org.nstack.header.message.APIParam;
import org.nstack.header.notification.ApiNotification;
import org.nstack.header.rest.APINoSee;
import org.nstack.header.rest.RestRequest;


@Action(category = L3NetworkConstant.ACTION_CATEGORY)
@RestRequest(
        path = "/l3-networks/ip-ranges/{uuid}",
        method = HttpMethod.DELETE,
        responseClass = APIDeleteIpRangeEvent.class
)
public class APIDeleteIpRangeMsg extends APIDeleteMessage implements L3NetworkMessage, IpRangeMessage {

    @APIParam(resourceType = IpRangeVO.class, successIfResourceNotExisting = true,
            checkAccount = true, operationTarget = true)
    private String uuid;

    @APINoSee
    private String l3NetworkUuid;

    public APIDeleteIpRangeMsg() {
    }

    public APIDeleteIpRangeMsg(String uuid) {
        super();
        this.uuid = uuid;
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public void setL3NetworkUuid(String l3NetworkUuid) {
        this.l3NetworkUuid = l3NetworkUuid;
    }

    @Override
    public String getL3NetworkUuid() {
        return l3NetworkUuid;
    }

    @Override
    public String getIpRangeUuid() {
        return uuid;
    }
 
    public static APIDeleteIpRangeMsg __example__() {
        APIDeleteIpRangeMsg msg = new APIDeleteIpRangeMsg();
        msg.setUuid(uuid());
        return msg;
    }

    public ApiNotification __notification__() {
        APIMessage that = this;

        return new ApiNotification() {
            @Override
            public void after(APIEvent evt) {
                ntfy("Deleted an IP range[uuid:%s]", getIpRangeUuid()).resource(l3NetworkUuid, L3NetworkVO.class.getSimpleName())
                        .resource("ipRangeUuid", getIpRangeUuid())
                        .messageAndEvent(that, evt).done();
            }
        };
    }
}
